﻿
(function () {
    appModule.controller('common.views.disputeInformations.reminders', [
        '$scope', '$uibModalInstance', 'abp.services.app.disputeInformation', 'disputeInformationId', 'abp.services.app.disputeType', 'disputeInformation', 'abp.services.app.area', '$http', 'abp.services.app.user',
        function ($scope, $uibModalInstance, disputeInformationService, disputeInformationId, disputeTypeService, disputeInformation, areaService, $http, userService) {
            var vm = this;
            vm.saving = false;
            //首先将disputeInformation数据设置为null
            vm.disputeInformation = null;
            vm.reminders = {
                id: disputeInformationId,
                userID: 0,
                remark: ''
            };



            //触发保存方法
            vm.save = function () {
                vm.saving = true;
                disputeInformationService.reminders(vm.reminders).then(function () {

                    //验证
                    if (vm.disputeInformation.clientID == '' || vm.disputeInformation.clientID == null) {
                        abp.message.warn(app.localize('NotClientID'), '提示');
                        vm.saving = false;
                        return;
                    }

                    //消息推送
                    $http({
                        method: 'POST',
                        url: 'http://61.162.225.227:8001/api/Values/ToMessage',
                        params: {
                            title: "催办消息",
                            content: vm.reminders.remark,
                            clientID: vm.disputeInformation.clientID
                        }
                    }).then(function successCallback(response) {
                        // 请求成功执行代码
                        var dd = response;
                    }, function errorCallback(response) {
                        // 请求失败执行代码
                        var dd = response;
                    });

                    abp.notify.info(app.localize('SavedSuccessfully'));
                    $uibModalInstance.close();
                }).finally(function () {
                    vm.saving = false;
                });


            };
            //取消关闭页面
            vm.cancel = function () {
                $uibModalInstance.dismiss();
            };

            //初始化页面
            function init() {
                disputeInformationService.getDisputeInformationForEditAsync({
                    id: disputeInformationId
                }).then(function (result) {
                    vm.disputeInformation = result.data.disputeInformation;
                    vm.reminders.userID = vm.disputeInformation.userID;

                });
            }

            //执行初始化方法
            init();
        }
    ]);

})();